#include "lsb/dump_embedding_engine.h"

/* rpoisel: this embedding engine is a decorator of the LSB 
 * embedding engine so search for configuration directives 
 * there
 */
const std::string CDumpEmbeddingEngine::sIniSectionName("LSB");

CDumpEmbeddingEngine::CDumpEmbeddingEngine(
		IBitSource* pBitSource,
		const std::string& pSendOriginalSampleFile,
		const std::string& pSendModifiedSampleFile,
		const std::string& pRecvModifiedSampleFile) :
	CLSBEmbeddingEngine(NULL),
	mSendOriginalSampleStream(pSendOriginalSampleFile.c_str(), std::ios::out | std::ios::binary | std::ios::trunc),
	mSendModifiedSampleStream(pSendModifiedSampleFile.c_str(), std::ios::out | std::ios::binary | std::ios::trunc),
	mRecvModifiedSampleStream(pRecvModifiedSampleFile.c_str(), std::ios::out | std::ios::binary | std::ios::trunc)
{
	mEmbeddingEngine = new CLSBEmbeddingEngine(pBitSource);
}

CDumpEmbeddingEngine::~CDumpEmbeddingEngine()
{
	delete mEmbeddingEngine;
	mSendOriginalSampleStream.close();
	mSendModifiedSampleStream.close();
	mRecvModifiedSampleStream.close();
}

std::string CDumpEmbeddingEngine::getIniSectionName() const
{
	return CDumpEmbeddingEngine::sIniSectionName;
}

int CDumpEmbeddingEngine::embedIntoSamples(int8_t* pSamples, unsigned int pCount, unsigned int pLeak)
{
	return mEmbeddingEngine->embedIntoSamples(pSamples, pCount, pLeak);
}

int CDumpEmbeddingEngine::embedIntoSamples(uint8_t* pSamples, unsigned int pCount, unsigned int pLeak)
{
	int lReturn(1);
	char lSample(pSamples[0]);
	
	mSendOriginalSampleStream.write(&lSample, 1);

	lReturn = mEmbeddingEngine->embedIntoSamples(pSamples, pCount, pLeak);

	lSample = pSamples[0];
	mSendModifiedSampleStream.write(&lSample, 1);

	return lReturn;
}

int CDumpEmbeddingEngine::embedIntoSamples(int16_t* pSamples, unsigned int pCount, unsigned int pLeak)
{
	return mEmbeddingEngine->embedIntoSamples(pSamples, pCount, pLeak);
}

int CDumpEmbeddingEngine::embedIntoSamples(uint16_t* pSamples, unsigned int pCount, unsigned int pLeak)
{
	return mEmbeddingEngine->embedIntoSamples(pSamples, pCount, pLeak);
}

int CDumpEmbeddingEngine::extractFromSamples(int8_t* pSamples, unsigned int pCount, unsigned int pLeak, unsigned int pInBuffer)
{
	return mEmbeddingEngine->extractFromSamples(pSamples, pCount, pLeak, pInBuffer);
}

int CDumpEmbeddingEngine::extractFromSamples(uint8_t* pSamples, unsigned int pCount, unsigned int pLeak, unsigned int pInBuffer)
{
	char lSample(pSamples[0]);
	
	mRecvModifiedSampleStream.write(&lSample,1);
	return mEmbeddingEngine->extractFromSamples(pSamples, pCount, pLeak, pInBuffer);
}

int CDumpEmbeddingEngine::extractFromSamples(int16_t* pSamples, unsigned int pCount, unsigned int pLeak, unsigned int pInBuffer)
{
	return mEmbeddingEngine->extractFromSamples(pSamples, pCount, pLeak, pInBuffer);
}

int CDumpEmbeddingEngine::extractFromSamples(uint16_t* pSamples, unsigned int pCount, unsigned int pLeak, unsigned int pInBuffer)
{
	return mEmbeddingEngine->extractFromSamples(pSamples, pCount, pLeak, pInBuffer);
}

